package cn.zwx.member.svc.config;

import org.apache.dubbo.apidocs.EnableDubboApiDocs;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zhangwenxue
 */
@EnableDubboApiDocs
@Configuration
public class DubboDocConfig {

    @Resource
    DubboConfigurationProperties properties;

    @ConditionalOnMissingBean
    @Bean
    ApplicationConfig application() {

        if (properties != null && properties.getApplication() != null) {
            return properties.getApplication();
        }
        //当前应用配置信息 ，如服务名
        return new ApplicationConfig();
    }

    @Bean
    @ConditionalOnMissingBean
    RegistryConfig registry() {
        if (properties != null && properties.getRegistry() != null) {
            return properties.getRegistry();
        }
        //注册中心配置
        return new RegistryConfig();
    }

    @Bean
    @ConditionalOnMissingBean
    ProtocolConfig protocol() {
        if (properties != null && properties.getProtocol() != null) {
            return properties.getProtocol();
        }
        // 服务传输协议的配置
        return new ProtocolConfig();
    }

}
